<?php

namespace App\Http\Requests\AuthRequests;

use Illuminate\Foundation\Http\FormRequest;

class PhoneRegisterRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'mobile' => ['required', 'unique:users,mobile', 'max:20'],
            'sms_code' => [
                'required',
                 'smsCode:+86' . $this->input('mobile')
            ],
            'password' => ['required', 'min:6', 'max:18'],
            'pay_password' => ['required', 'min:6', 'max:18'],
            'invitation_code' => 'required|string',
//            'parent_id' => ['required'],
        ];
    }

    public function messages()
    {
        return [
            'mobile.required' => __('手机号必填'),
            'mobile.unique' => __('账号已注册'),
            'mobile.max' => __('账号至多20位'),
            'mobile.num' => __('账号只能包含数字'),
            'code.required' => __('验证码必填'),
            'password.required' => __('登录密码必填'),
            'password.min' => __('登录密码至少6位'),
            'password.max' => __('登录密码至多18位'),
            'pay_password.required' => __('交易密码必填'),
            'pay_password.min' => __('交易密码至少6位'),
            'pay_password.max' => __('交易密码至多18位'),
            'parent_id.required' => __('请填写邀请码'),
            'invitation_code.required' => __('请填写邀请码'),
            'invitation_code.string' => __('邀请码必须是字符串类型'),
        ];
    }
}
